<?php
/**
 * Created by PhpStorm.
 * User: 刘抱
 * Date: 2018/10/11
 * Time: 11:13
 */

namespace Home\Controller;


use Qywx\Controller\BaseController;

class EnterpriseWeChatController extends CommunalController
{
    //推送模块列表
    public function push()
    {
        $db_push_notification = M("db_push_notification");
        $result = $db_push_notification->select();
        $count = count($result);
        $Page = new \Think\Page($count, 15);
        $result = array_slice($result, $Page->firstRow, $Page->listRows);
        $show = $Page->show();
        $this->assign('result', $result);
        $this->assign('page', $show);
        $this->display();
    }

    //修改推送模块通知部门或人
    public function edit()
    {
        $id = I("id");
        $db_push_notification = M("db_push_notification");
        $res_push = $db_push_notification->where("id=$id")->find();
        $Qywx = new BaseController();
        $res_departments = $Qywx->get_department('');
        $userList = get_userName('');
        $department_ids = explode(',', $res_push['push_department_id']);
        $user_ids = explode(',', $res_push['push_user_id']);
        $this->assign('user_list', $userList);
        $this->assign('res_push', $res_push);
        $this->assign('res_departments', $res_departments);
        $this->assign('department_ids', $department_ids);
        $this->assign('user_ids', $user_ids);

        if (!empty($_POST)) {
            $data = $_POST;
            $data['push_department_id'] = implode(',', $data['push_department_id']);
            $data['push_user_id'] = implode(',', $data['push_user_id']);
            try {
                $db_push_notification->where("id=$id")->save($data);
                $this->success('更新成功', __APP__ . 'EnterpriseWeChat/push');
                die;
            } catch (\Exception $e) {
                $this->error('更新失败', __APP__ . 'EnterpriseWeChat/push');
                die;
            }
        }
        $this->display();
    }

    //企业微信通知记录
    public function push_log()
    {
        $db_push_log = M("db_push_log");
        $result = $db_push_log->select();
        $showlist = $this->show_page($result);
        $this->assign('page',$showlist['show']);
        $this->assign('result',$showlist['result']);
        $this->display();
    }

}